// lib/home_page.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'theme/theme_manager.dart'; // 确保导入路径正确

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  @override
  Widget build(BuildContext context) {
    print("HomePage重建"); // 添加重建日志
    final themeManager =
        Provider.of<ThemeManager>(context, listen: true); // 确保listen为true
    final theme = Theme.of(context);

    return Scaffold(
      appBar: AppBar(
        title: const Text('鸿蒙主题适配'),
        actions: [
          IconButton(
            icon: const Icon(Icons.brightness_6),
            onPressed: themeManager.toggleTheme,
          ),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              '当前主题',
              style: theme.textTheme.titleLarge,
            ),
            const SizedBox(height: 20),
            Text(
              theme.brightness == Brightness.light ? '浅色模式' : '深色模式',
              style: theme.textTheme.bodyLarge,
            ),
            const SizedBox(height: 40),
            Text(
              '使用方法:根据系统设置主题颜色,返回应用查看颜色是否自动适配',
              style: theme.textTheme.titleLarge,
            ),
            const SizedBox(height: 30),
          ],
        ),
      ),
    );
  }
}
